/**
 * LogKaiyuanService.java
 * Copyright(C) 1949++ 中华人民共和国
 * 深圳市盛开互联网金融顾问有限公司.
 * All rights reserved.
 * E-mail:server@skjr.net
 * SKDate:2017-11-16 17:28:58
 */
package com.huamao.zh.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.huamao.zh.base.PageWrapper;
import com.huamao.zh.constants.KaiyuanType;
import com.huamao.zh.mapper.LogKaiyuanMapper;
import com.huamao.zh.model.LogKaiyuan;
import com.huamao.zh.service.LogKaiyuanService;

@Service
@Transactional
public class LogKaiyuanServiceImpl implements LogKaiyuanService {

	@Autowired
	private LogKaiyuanMapper logKaiyuanMapper;

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuan add(LogKaiyuan logKaiyuan) throws Exception {
		logKaiyuanMapper.add(logKaiyuan);
		return logKaiyuan;
	}

	public LogKaiyuan add(int type, int fromId, int userId, String orderNo, int scoreType, BigDecimal preKaiyuan,
			int kaiyuanType, BigDecimal getKaiyuan, String remark) throws Exception {
		LogKaiyuan logKaiyuan = new LogKaiyuan();
		logKaiyuan.setType(type);
		logKaiyuan.setFromId(fromId);
		logKaiyuan.setUserId(userId);
		logKaiyuan.setOrderNo(orderNo);
		logKaiyuan.setPreKaiyuan(preKaiyuan);
		logKaiyuan.setKaiyuanType(kaiyuanType);
		logKaiyuan.setKaiyuan(getKaiyuan);
		logKaiyuan.setRemark(remark);
		logKaiyuan.setDataFlag(1);
		logKaiyuan.setCreateTime(new Date());
		logKaiyuanMapper.add(logKaiyuan);
		return logKaiyuan;
	}

	/**
	 * 功能说明：生成日志专用 Author：spring Date：2017/11/21 8:54
	 */
	public LogKaiyuan getLogKaiyuan(KaiyuanType type, int fromId, int userId, String orderNo, BigDecimal preKaiyuan,
			BigDecimal kaiyuan, String remark) {
		LogKaiyuan logKaiyuan = new LogKaiyuan();
		logKaiyuan.setType(type.getCode());
		logKaiyuan.setFromId(fromId);
		logKaiyuan.setUserId(userId);
		logKaiyuan.setOrderNo(orderNo);
		logKaiyuan.setPreKaiyuan(preKaiyuan);
		logKaiyuan.setKaiyuan(kaiyuan);
		logKaiyuan.setRemark(remark);
		logKaiyuan.setDataFlag(1);
		logKaiyuan.setCreateTime(new Date());
		return logKaiyuan;
	}

	/**
	 * 功能说明：添加 新增 流水 Author：spring Date：2017/11/21 8:56
	 */
	@Override
	public LogKaiyuan sumKaiyuan(KaiyuanType type, Integer fromId, Integer userId, String orderNo, BigDecimal preCash,
			BigDecimal cash, String remark) throws Exception {
		LogKaiyuan logKaiyuan = getLogKaiyuan(type, fromId, userId, orderNo, preCash, cash, remark);
		logKaiyuan.setKaiyuanType(1);
		return this.add(logKaiyuan);
	}

	/**
	 * 功能说明：添加 减少 流水 Author：spring Date：2017/11/21 8:56
	 */
	@Override
	public LogKaiyuan subtractKaiyuan(KaiyuanType type, Integer fromId, Integer userId, String orderNo,
			BigDecimal preCash, BigDecimal cash, String remark) throws Exception {
		LogKaiyuan logKaiyuan = getLogKaiyuan(type, fromId, userId, orderNo, preCash, cash, remark);
		logKaiyuan.setKaiyuanType(0);
		return this.add(logKaiyuan);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuan addSelective(LogKaiyuan logKaiyuan) throws Exception {
		logKaiyuanMapper.addSelective(logKaiyuan);
		return logKaiyuan;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int delete(Map<String, Object> map) {
		return logKaiyuanMapper.delete(map);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int update(LogKaiyuan logKaiyuan) throws Exception {
		return logKaiyuanMapper.update(logKaiyuan);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int updateSelective(LogKaiyuan logKaiyuan) throws Exception {
		return logKaiyuanMapper.updateSelective(logKaiyuan);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuan get(Integer id) {
		LogKaiyuan logKaiyuan = logKaiyuanMapper.get(id);
		return logKaiyuan;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public PageWrapper<LogKaiyuan> search(PageWrapper<LogKaiyuan> pageWrapper) {
		List<LogKaiyuan> logKaiyuans = logKaiyuanMapper.search(pageWrapper);
		pageWrapper.setList(logKaiyuans);
		return pageWrapper;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public List<LogKaiyuan> queryList(Map<String, Object> map) {
		return logKaiyuanMapper.queryList(map);
	}
}